package com.yztc.orangeentertainment.ui.main.channalfragment;

import com.yztc.orangeentertainment.bean.channalbean.ChannalTitle;
import com.yztc.orangeentertainment.bean.channalbean.ChannalTitleDataBean;
import com.yztc.orangeentertainment.config.ChannalUrlConfig;
import com.yztc.orangeentertainment.http.ChannalRetrofitService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/5.
 */
public class ChannalModle implements ChannalContract.Modle{


    @Override
    public void getChannalTitle(final OnLoadChannalListener loadChannalListener) {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(ChannalUrlConfig.PATH.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<ChannalTitle> call=retrofit.create(ChannalRetrofitService.class)
                .getChannalTitles();
        call.enqueue(new Callback<ChannalTitle>() {
            @Override
            public void onResponse(Call<ChannalTitle> call, Response<ChannalTitle> response) {
                List<ChannalTitleDataBean> list=response.body().getData();
                loadChannalListener.onSuccess(list);
            }

            @Override
            public void onFailure(Call<ChannalTitle> call, Throwable t) {
                loadChannalListener.onFailure(t.getMessage());
            }
        });
    }

    @Override
    public void getChannalTitleFromDb(Call<ChannalTitle> call) {

    }
}
